<?php

include_once("{$_SERVER['DOCUMENT_ROOT']}/header.php");
include_once(PHP_ROOT . "/class/db/bbs/BbsListManager.php");

//오버라이딩
class CList extends BbsListManager {

    function cate_list() {
        $list.="<select class='w_200 h_20' id='" . $this->layer_id . "_cate' onChange=\"bbs.cateChange(this);\"> <option value='0'>-----이동할 카테고리-----</option>";
        $sql = "select* from tb_board_division";
        $r = $this->get_result($sql);
        while ($result = $r->fetch_assoc()) {
            $list.= "<option value='{$result['board_table']}'>{$result['board_description']}</option>";
        }
        $list.="</select>";
        return $list;
    }

    function set_style() {
        global $SESSION_ALL_EXCUTE;
        global $SESSION_DEL;
        global $SESSION_MOD;

        global $FOLDER_PATH;
        global $BBS_PATH;
        global $PAGE_ALL_DEL_OK;
        global $PAGE_ALL_MOVE_OK;
        global $PAGE_LIST;
        global $FOLDER_PATH_PHP;
        global $PAGE_DEL;
        global $PAGE_MOD;

        $_F = new Func();
        $token = $_F->makeToken($SESSION_ALL_EXCUTE);
        $token_del = $_F->makeToken($SESSION_DEL);
        $token_mod = $_F->makeToken($SESSION_MOD);

        $odd = 1;
        $cate_list = $this->cate_list();
        $admin = "
                    <tr >
                         <td class='left w_50' bgcolor='#ffffff'>
                        <input  type='checkbox' class='all_check_box' onClick=\"bbs.all_check_box('$this->layer_id',this);\"> *
                        </td>
                        <td colspan='100' bgcolor='#ffffff' style=\"text-align:left; \">
                            <input type='button' class='h_20' value='삭제' onClick=\"bbs.allExcute('$PAGE_ALL_DEL_OK','$this->layer_id','$token');\">
                            
                            <select class='h_20'  id='listCount' title='보여질 리스트숫자' onChange=\"var l = $(this).val();bbs.swapPage('$PAGE_LIST&num='+l,'$this->layer_id');\" > 
                            <option value='10'>10줄</option>
                            <option value='15'>15줄</option>
                            <option value='20'>20줄</option>
                            <option value='30'>30줄</option>
                            <option value='50'>50줄</option>
                            <option value='100'>100줄</option>
                            <option value='1000'>1000줄</option>
                            <option value='10000'>10000줄</option>
                            </selcet>
                         </td>
                    </tr>";
        if ($this->getAdmin() == true) {
            echo"$admin";
        }
        while ($result = $this->result->fetch_object()) {

            $sql = "select user_level from tb_users where user_num = '{$result->user_num}'";
            // $user = $this->db->query($sql);
            $user = $this->db->query($sql)->fetch_assoc();
            if (!$user['user_level']) {
                $user['user_level'] = 0;
            }
            $user_img = "<div><img src='/noritu/img/level_{$user['user_level']}.png'></div>";


            //관리자모드일때 체크박스표시
            if ($this->getAdmin() == true) {
                $all_check_box = "<input type='checkbox'  value='$result->uid'>";
            } else {
                $all_check_box = "";
            }
            //홀수짝수구분해서 색지정
            if ($odd % 2 == 0) {
                $line_color = "#E5E5E5";
            } else {
                $line_color = "";
            }
            //댓글이면 공백문자 추가
            for ($i = 0; $i < $result->comment_depth; $i++) {
                $depth .="&nbsp;&nbsp;&nbsp;";
            }
            if ($i > 0) {
                $depth .="<img  src='" . SCRIPT_ROOT . "/img/icon/re.gif' border='0'style=\"width:8px; height:8px;\" align='absmiddle'>";
            }
            //글자 길이 제한

            $name_tmp = $_F->cutStringByUtf8($result->user_nick, 12, true, ''); //인자가 홀수일때 한글이 안깨짐
            $title = $_F->cutStringByUtf8($result->board_subject, 60, true, '');
            $date = $_F->getDateFormat($result->reg_date, 1);



            $name = "<div  class='hand inline'  onClick=\"bbs.loadMenu('member_info','{$FOLDER_PATH}/user_info.php?user_num={$result->user_num}','300','180',$(this).offset());\">$name_tmp</div>";



            //비로그인 글쓰기 하면 
            if (!$result->user_num) {
                $name = "<div style=\"color:gray;\">$name_tmp</div>";

                $user_img = "";
            }


            //시간계산
            $now = date("Y-m-d H:i:s");
            $end = $result->reg_date;

            $time = strtotime($now) - strtotime($end);

            $mm = ceil($time / 60);
            $h = 0;
            $m = ceil($mm % 60);


            if ($time >= 3600) {
                $h = ceil($time / 3600);
            } else {
                $h = 0;
            }


            //24시간 안된글
            if ($h >= 24) {

                $new_list = "";
            } else {
                if ($h > 0) {
                    $htime = "$h 시간";
                } else {
                    $htime = "";
                }
                $date = "<span class='red inline'>$htime $m 분 </span>전";
                $new_list = "<img src='/noritu/img/new_icon2.png' align='absmiddle'>";
            }


            if ($result->comment_depth == 0) {
                //  $comment_input = "  <input type='image' value='댓글' title='댓글' src='$FOLDER_PATH/img/bt_reply.gif' onClick=\"bbs.moveCommnetForm('$result->ord_num','$result->uid'); \">";
            } else {
                $comment_input = "";
            }
            $this_bbs = "&bbs_uid=$result->uid&bbs_sort=$result->sort"; // 현재의 글을 의미한다.
            //오버라이딩 구역 시작
            echo("            <table class='w_100p' style='border-bottom:1px dotted gray; '>
                                   <tr>
                                      <td class='right'>$all_check_box $depth
                                      </td>
                                      <td>
                                                    <table class='bbs w_100p'>
                                                    <tr>
                                                        <td class='w_20p'>
                                                        $name ($date)
                                                        </td>
                                                        <td class='w_80p'>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan='100' class='h_100 top'>
                                                           $result->comment_text
                                                        </td>
                                                    </tr>


                                                     <tr>
                                                        <td colspan='100' class='right'>
                                                                <input type='image' value='수정' title='수정' src='$FOLDER_PATH/img/bt_modify.gif' onClick=\"bbs.showDiv('mod_$result->uid');\">
                                                                <input type='image' value='삭제' title='삭제' src='$FOLDER_PATH/img/bt_delete.gif' onClick=\"bbs.showDiv('del_$result->uid'); \">
                                                                   $comment_input
                                                                   <div id='mod_$result->uid' style='display: none; height: 30px;'>
                                                                     <input type='password' id='mod_passwd_$result->uid' onmouseover=\"bbs.getFocus(this);\">
                                                                     <input type='image' value='수정' title='수정' src=' $FOLDER_PATH/img/bt_modify.gif'  onClick=\"var pw = $('#mod_passwd_$result->uid').val();  bbs.swapPage('$PAGE_MOD" . "$this_bbs&pw='+pw,'$this->layer_id','','html','','$token_mod');\">
                                                                     <a onClick=\"bbs.hideDiv('mod_$result->uid'); return false\"><img src=' $FOLDER_PATH/img/bt_x.gif' border=0></a>
                                                                   </div>
                                                                   <div id='del_$result->uid' style='display: none; height: 30px;'>
                                                                     <input type='password' id='del_passwd_$result->uid' onmouseover=\"bbs.getFocus(this);\">
                                                                     <input type='image' value='삭제' title='삭제' src=' $FOLDER_PATH/img/bt_delete.gif' onClick=\"var pw = $('#del_passwd_$result->uid').val();  bbs.swapPage('$PAGE_DEL" . "$this_bbs&pw='+pw,'$this->layer_id','','html','','$token_del'); \">
                                                                     <a onClick=\"bbs.hideDiv('del_$result->uid'); return false \"><img src=' $FOLDER_PATH/img/bt_x.gif' border=0></a>
                                                        </td>
                                                    </tr>
                                                    </table>
                                     </td>
                                 </tr>
                            </table>
                                      
					");
            //오버라이딩 구역 끝
            $depth = "";
            $odd++;
        }
    }

    //총줄수 필요하면 오버라이딩
    function get_rows() {
        $rows = $this->get_count($this->table, "where buid ='$this->parent_uid' and user_deleted ='0'  $this->where");
        return $rows;
    }

    function show_list() {
        $sql = "select * from $this->table  where  buid ='$this->parent_uid'  and user_deleted ='0' $this->where  order by $this->order_by asc     limit $this->start_no,$this->end_no";
        // CASE WHEN(ruid > 0) THEN $this->order_by  END asc , CASE WHEN(ruid < 0) THEN $this->order_by  END desc
        $result = $this->get_result($sql);
        $this->result = $result;
        $this->set_style();
    }

    function show_list_jump() {

        $k = 5;
        $until = $this->page + $k;
        if ($this->page <= 5) {
            $until = 10;
        }
        if ($until >= ($this->total_pages - 1)) {
            $until = $this->total_pages;
        }

        for ($i = ($this->page - $k); $i < $until; $i++) {
            $k++;
            if ($i <= 0) {
                $i = 0;
            }
            if ($this->page == $i) {
                $colorAndBold = "style=\"color:red; font-weight: bold;\"";
            } else {
                $colorAndBold = "";
            }
            $a = $i + 1;

            $list .= " <b><a onClick=\"bbs.swapPage('$this->target_url?bbs_mode=&table=$this->table&page=$i&key_search=$this->key_search&key_search_field=$this->key_search_field&layer_id=$this->layer_id&category=$this->category&num=$this->end_no&order_by=$this->order_by&parent_uid=$this->parent_uid','$this->layer_id');\" class='pageNum' $colorAndBold>$a</a></b> ";

            $back = $this->page + 1;
            $back10 = $this->page + 10;
            $front = $this->page - 1;
            $front10 = $this->page - 10;



            if ($back >= $this->total_pages) {
                $back = $this->total_pages - 1;
            }
            if ($back10 >= $this->total_pages) {
                $back10 = $this->total_pages - 1;
            }
            if ($front >= $this->total_pages) {
                $front = $this->total_pages - 1;
            }
            if ($front10 >= $this->total_pages) {
                $front10 = $this->total_pages - 1;
            }

            if ($back <= 0) {
                $back = 0;
            }
            if ($back10 <= 0) {
                $back10 = 0;
            }
            if ($front <= 0) {
                $front = 0;
            }
            if ($front10 <= 0) {
                $front10 = 0;
            }

            $go1 = "<img src='" . SCRIPT_ROOT . "/img/icon/play.png' border='0' width='16' height='16' align='absmiddle'>";
            $back1 = "<img src='" . SCRIPT_ROOT . "/img/icon/playBack.png' border='0' width='16' height='16' align='absmiddle'>";
            $go2 = "<img src='" . SCRIPT_ROOT . "/img/icon/fast forward.png' border='0' width='16' height='16' align='absmiddle'>";
            $back2 = "<img src='" . SCRIPT_ROOT . "/img/icon/skip forward.png' border='0' width='16' height='16' align='absmiddle'>";

            $b = "<b><a onClick=\"bbs.swapPage('$this->target_url?bbs_mode=&table=$this->table&page=$back&key_search=$this->key_search&key_search_field=$this->key_search_field&layer_id=$this->layer_id&category=$this->category&num=$this->end_no&order_by=$this->order_by&parent_uid=$this->parent_uid','$this->layer_id');\" class='pageNum' $colorAndBold> $go1 </a></b>";
            $f = "<b><a onClick=\"bbs.swapPage('$this->target_url?bbs_mode=&table=$this->table&page=$front&key_search=$this->key_search&key_search_field=$this->key_search_field&layer_id=$this->layer_id&category=$this->category&num=$this->end_no&order_by=$this->order_by&parent_uid=$this->parent_uid','$this->layer_id');\" class='pageNum' $colorAndBold> $back1 </a></b>";
            $bb = "<b><a onClick=\"bbs.swapPage('$this->target_url?bbs_mode=&table=$this->table&page=$back10&key_search=$this->key_search&key_search_field=$this->key_search_field&layer_id=$this->layer_id&category=$this->category&num=$this->end_no&order_by=$this->order_by&parent_uid=$this->parent_uid','$this->layer_id');\" class='pageNum' $colorAndBold> $go2 </a></b>";
            $ff = "<b><a onClick=\"bbs.swapPage('$this->target_url?bbs_mode=&table=$this->table&page=$front10&key_search=$this->key_search&key_search_field=$this->key_search_field&layer_id=$this->layer_id&category=$this->category&num=$this->end_no&order_by=$this->order_by&parent_uid=$this->parent_uid','$this->layer_id');\" class='pageNum' $colorAndBold> $back2 </a></b>";
            $thisPage = $this->page + 1;
        }
        echo "$ff $f $list $b $bb ";
    }

}
